React 您所在的位置:网站首页 掘金 react native 组件库 React

React

2023-07-10 01:28| 来源: 网络整理| 查看: 265

import React, { FC, useEffect, useRef, useState, Fragment, useMemo } from 'react';

import { LoadingProps } from './interface';

import './index.module.less';

const Loading: FC = (props) => {

  const {

    type = 'default',

    mask = false,

    loadingText,

    icon,

    width = '2em',

    height = '2em',

    style = {},

  } = props;

  const timer = useRef(null);

  const [activeDotIndex, setActiveDotIndex] = useState(0);

  useEffect(() => {

    timer.current = setInterval(() => {

      setActiveDotIndex((old) => {

        if (old === 2) {

          old = 0;

        } else {

          old++;

        }

        return old;

      });

    }, 500);

    return () => {

      clearInterval(timer.current);

    };

  }, []);

  const loadingStyle = useMemo(() => {

    const returnStyle = style;

    returnStyle.width = width;

    returnStyle.height = height;

    return returnStyle;

  }, [width, height, style]);

  return (

    

      {mask && }

      {type === 'default' ? (

        

          

            {icon || (

              

                

              

            )}

          

          {loadingText && {loadingText}}

        

      ) : (

        

          {new Array(3).fill('').map((item, index) => {

            return {item};

          })}

        

      )}

    

  );

};

export default Loading;



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有